﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class UIManager : MonoBehaviour {
    public GameObject MainInterface; //主界面
    public GameObject SelectLevel;// 选择关卡界面
    public GameObject SetUp;//设置界面
    public GameObject Success;//成功界面
    public GameObject Defeated;//失败界面

    public Button StartGameButton;// 开始游戏按钮
    public Button setUpButton; //设置按钮
    public Button ExitButton; //退出按钮
    public Button ReturnLevel;//返回关卡按钮



    public AudioSource audioSource1; //背景音乐组件
    public Slider slider1; //背景音乐控制条

    public AudioSource audioSource2;  //游戏音效组件
    public Slider slider2; //游戏音效控制条

    public Button ReturnButton; //返回按钮
    public Button SetUpButton; //设置按钮

    // Use this for initialization
    void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {
        audioSource1.volume = slider1.value;
        audioSource2.volume = slider2.value;
    }

    /// <summary>
    /// 点击开始按钮
    /// </summary>
    public void OnClickStartGameButton()
    {
        SelectLevel.SetActive(true);
    }

    /// <summary>
    /// 点击第三关按钮
    /// </summary>
    public void OnClickThreeLevel()
    {
        SceneManager.LoadScene(1);
    }


    /// <summary>
    /// 点击设置按钮
    /// </summary>
    public void OnClickSetUpButton()
    {

        SetUp.SetActive(true);//打开设置界面
        audioSource1 = GameObject.FindGameObjectWithTag("MainCamera").transform.GetComponent<AudioSource>();//找到背景音乐组件
        slider1 = GameObject.Find("SliderBGMusic").transform.GetComponent<Slider>();//找到背景音乐控制条

        audioSource2 = GameObject.Find("Canvas").transform.GetComponent<AudioSource>();//找到游戏音效
        slider2 = GameObject.Find("SliderGameMusic").transform.GetComponent<Slider>();//找到游戏音效控制条

       // SetUpButton = GameObject.Find("SetUpButton").GetComponent<Button>();//找到设置按钮
      //  SetUpButton.gameObject.SetActive(false);//关闭设置按钮


    }

    /// <summary>
    /// 点击返回关卡按钮
    /// </summary>
    public void OnClickReturnLevelButton()
    {
        SelectLevel.SetActive(true);//打开选择关卡界面
        Defeated.SetActive(false);//关闭失败界面
        Success.SetActive(false);//关闭成功界面
    }

    /// <summary>
    /// 点击返回主界面
    /// </summary>
    public void GoBackReturnButton()
    {
        SetUp.SetActive(false);//关掉设置界面      
    }
}
